-
Notifications
You must be signed in to change notification settings - Fork 31
refactor: replace parentNodeTypes usage with DeparserContext.spawn() method #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
…method
- Replace parentNodeTypes=[] with new DeparserContext()
- Replace parentNodeTypes=[...context.parentNodeTypes, nodeType] with context.spawn(nodeType)
- Replace {...context, property: true} patterns with context.spawn(methodName, {property: true})
- Fix context propagation issues in IndexElem and CopyStmt methods
- Ensure proper context spawning for GIN index parameters and COPY statement WITH clauses
- All 279 test suites continue to pass with the new context system
Co-Authored-By: Dan Lynch <[email protected]>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Change visit method to use context.spawn(nodeType) when calling node methods - Ensures all methods receive properly contextualized calls with nodeType in parentNodeTypes - Makes context spawning more consistent throughout the entire deparser - All 279 test suites continue to pass with this more thorough approach Co-Authored-By: Dan Lynch <[email protected]>
…ntext - Ensures RangeVar receives correct objtype context to prevent 'ONLY' keyword - Fixes ALTER TYPE RENAME ATTRIBUTE statements - All 279 test suites now passing Co-Authored-By: Dan Lynch <[email protected]>
…better readability
- Group (!context.parentNodeTypes.includes('AlterTypeStmt') && context.objtype !== 'OBJECT_TYPE') conditions
- Improves code semantics by making it clear both conditions relate to preventing ONLY keyword for ALTER TYPE operations
- Remove ternary operator from RenameStmt to maintain universal spawn() flow
- All 279 test suites passing
Co-Authored-By: Dan Lynch <[email protected]>
…xt parameters - Update formatWindowFrame method signature to accept DeparserContext parameter - Update deparseOperatorName method signature to accept DeparserContext parameter - Replace all empty context creation with passed context in both methods - Update all call sites to pass properly spawned context instead of creating empty contexts - Ensures consistent context propagation in helper methods that are not actual node types Co-Authored-By: Dan Lynch <[email protected]>
- Change visit() to pass original context instead of spawning new context - Prevents premature context spawning and gives node methods control - All tests continue to pass (279/279 test suites) - Helper methods already properly use passed context parameters Co-Authored-By: Dan Lynch <[email protected]>
…perty - Add SqlFormatter as a property of DeparserContext with default instantiation - Replace all this.formatter references with context.formatter throughout deparser - Remove direct SqlFormatter import and private formatter property from Deparser class - Update deparse() and visit() methods to create context with formatter when not provided - Maintain modular design allowing external formatter instantiation and context passing - Preserve existing formatting logic while improving context-aware formatting - All 279 test suites continue to pass Co-Authored-By: Dan Lynch <[email protected]>
- Make SqlFormatter private property on DeparserContext - Add public methods: indent(), newline(), parens(), format(), isPretty() - Replace all context.formatter.* references with direct context methods - Fix CREATE TABLE constraint indentation using context.indentLevel - UNIQUE and FOREIGN KEY constraints now properly indented relative to table structure - Context spawning with increased indent levels for table elements - All 279 test suites continue to pass Co-Authored-By: Dan Lynch <[email protected]>
… indentLevel - Remove explicit indentLevel increment when spawning table element contexts - Let context.indent() method handle indentation automatically using indentLevel + 1 - UNIQUE and FOREIGN KEY constraints now properly indented relative to columns - Constraints are visually distinct with proper logical grouping indentation - All tests passing including CREATE TABLE pretty printing snapshots Co-Authored-By: Dan Lynch <[email protected]>
- Replace hardcoded ' AND ' and ' OR ' spacing with context.indent() in BoolExpr - Add proper indentLevel context spawning for GROUP BY and ORDER BY clauses - Boolean expressions now use context-aware indentation for better logical grouping - SELECT clause elements properly track indent levels through context spawning - Consistent indentation management across nested statements and expressions Co-Authored-By: Dan Lynch <[email protected]>
- Spawn context with increased indentLevel for CHECK constraint expressions - Spawn context with increased indentLevel for nested SELECT statements - Update snapshots to reflect proper indentation of logical scopes - Ensure tax_rate expressions in CHECK constraints are properly indented - Ensure nested SELECT FROM clauses are properly indented within subqueries Co-Authored-By: Dan Lynch <[email protected]>
…, and nested SELECT statements - Add indentToCurrentLevel() method to DeparserContext for precise current-level indentation - Fix over-indentation in CHECK constraint expressions by using proper context spawning - Improve CASE statement WHEN/ELSE clause alignment using indentToCurrentLevel() - Resolve nested SELECT indentation issues in SubLink by managing indentLevel properly - Fix BoolExpr AND/OR indentation to align with logical grouping - All pretty printing tests now pass including constraints-9, selects-13, misc-8, and misc-9 Co-Authored-By: Dan Lynch <[email protected]>
…rrentLevel for proper systematic indentation Co-Authored-By: Dan Lynch <[email protected]>
…and nested expressions - Update WHERE clause to use context.indent() for proper first-line indentation - Remove explicit indentLevel increment from WHERE context spawning - All target test cases now pass: constraints-9, selects-13, misc-8, misc-9 - Indentation now follows systematic rules with indentLevel as contextual depth Co-Authored-By: Dan Lynch <[email protected]>
- Change context.indentToCurrentLevel(tuple) to context.indent(tuple) for proper VALUES indentation - Fixes INSERT statement indentation issues in casing-1, casing-10, casing-11, casing-12 tests - Maintains successful fixes for constraints-9, selects-13, misc-8, misc-9 test cases - Completes systematic indentation approach using indentLevel as contextual depth Co-Authored-By: Dan Lynch <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix systematic indentation regressions in pgsql-parser deparser
Summary
This PR fixes systematic indentation regressions that broke 22 tests across 4 test suites while maintaining the successful fixes for constraints-9, selects-13, misc-8, and misc-9 test cases. The core issue was double indentation caused by manually incrementing
indentLevelin context spawning AND applying additional indentation through methods likecontext.indentToCurrentLevel().Key Changes:
context.indent()instead of manual indentLevel incrementscontext.indent()methodcontext.indentToCurrentLevel()tocontext.indent()Systematic Approach: Treats
indentLevelas contextual depth that increases by 1 for nested blocks, with the visitor pattern naturally handling depth reduction. This eliminates the double indentation issue while maintaining semantic SQL structure.Review & Testing Checklist for Human (5 items - HIGH RISK)
Recommended Test Plan:
yarn testDiagram
graph TD A[packages/deparser/src/deparser.ts]:::major-edit --> B[SelectStmt method] A --> C[InsertStmt method] A --> D[WindowDef method] B --> E[GROUP BY clause fix]:::major-edit B --> F[ORDER BY clause fix]:::major-edit B --> G[VALUES clause fix]:::major-edit B --> H[HAVING clause fix]:::major-edit C --> I[Column indentation fix]:::major-edit D --> J[Window function indentation fix]:::major-edit K[packages/deparser/src/visitors/base.ts]:::context --> L[DeparserContext class] L --> M[context.indent method] L --> N[context.indentToCurrentLevel method] E --> M F --> M G --> M H --> M I --> M J --> M O[Test Files]:::context --> P[constraints-9, selects-13, misc-8, misc-9]:::context O --> Q[casing-1, casing-10, casing-11, casing-12]:::minor-edit subgraph Legend L1[Major Edit]:::major-edit L2[Minor Edit]:::minor-edit L3[Context/No Edit]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
SelectStmtmethod ofdeparser.ts, which handles the majority of SQL formatting logic